package com.ruoyi.material.controller;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.material.domain.MaterialInfo;
import com.ruoyi.material.service.IMaterialInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.material.domain.OutboundOrder;
import com.ruoyi.material.service.IOutboundOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出库Controller
 * 
 * @author ruoyi
 * @date 2022-08-25
 */
@RestController
@RequestMapping("/material/outboundOrder")
public class OutboundOrderController extends BaseController
{
    @Autowired
    private IOutboundOrderService outboundOrderService;

    /**
     * 查询出库列表
     */
    @PreAuthorize("@ss.hasPermi('material:outboundOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(OutboundOrder outboundOrder)
    {
        startPage();
        List<OutboundOrder> list = outboundOrderService.selectOutboundOrderList(outboundOrder);
        return getDataTable(list);
    }

    /**
     * 导出出库列表
     */
    @PreAuthorize("@ss.hasPermi('material:outboundOrder:export')")
    @Log(title = "出库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OutboundOrder outboundOrder)
    {
        List<OutboundOrder> list = outboundOrderService.selectOutboundOrderList(outboundOrder);
        ExcelUtil<OutboundOrder> util = new ExcelUtil<OutboundOrder>(OutboundOrder.class);
        util.exportExcel(response, list, "出库数据");
    }

    /**
     * 获取出库详细信息
     */
    @PreAuthorize("@ss.hasPermi('material:outboundOrder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(outboundOrderService.selectOutboundOrderById(id));
    }

    /**
     * 新增出库
     */
    @PreAuthorize("@ss.hasPermi('material:outboundOrder:add')")
    @Log(title = "出库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OutboundOrder outboundOrder)
    {
        return toAjax(outboundOrderService.insertOutboundOrder(outboundOrder));
    }

    /**
     * 修改出库
     */
    @PreAuthorize("@ss.hasPermi('material:outboundOrder:edit')")
    @Log(title = "出库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OutboundOrder outboundOrder)
    {
        return toAjax(outboundOrderService.updateOutboundOrder(outboundOrder));
    }

    /**
     * 删除出库
     */
    @PreAuthorize("@ss.hasPermi('material:outboundOrder:remove')")
    @Log(title = "出库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(outboundOrderService.deleteOutboundOrderByOutboundNo(ids));
    }
    /**
     * 出库操作
     * @param id
     * @return
     */
    @Log(title = "收料单信息", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('material:outboundOrder:status')")
    @GetMapping(value = "status/{id}")
    public AjaxResult changeStatus(@PathVariable("id") Long id){
        return outboundOrderService.changeStatus(id);
    }



}
